<?php
header("content-type:text/html;charset=utf8");

include('Page.php'); //引入类
require_once "../conn.php";
$sql = "select count(*) from userstb "; //查询表的所有记录
$rs = $conn->query($sql);
$count = 0;
if ($row = $rs->fetch_row())
    $count = $row['0']; //获取所有的记录
$page = isset($_GET['page']) ? $_GET['page'] : 1; //三元运算符
$subpage = 2; //每页显示2条记录
$offset = ($page - 1) * $subpage;
$sql = "select * from userstb limit $offset,$subpage";
$rs = $conn->query($sql);
while ($row = $rs->fetch_assoc()) {
    foreach ($row as $k => $v)
        echo "$k:$v &nbsp;&nbsp;";
    echo "<br>";
}
//$p=new Page(总条数,显示页数,当前页码,每页显示条数,[链接]);
//连接不设置则为当前链接

$p = new Page($count, 4, $page, $subpage);

//生成一个页码数组（键为页码，值为链接）
echo "<pre>";
print_r($p->getPages());

//样式 共45条记录,每页显示10条,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页]
echo $p->showPages(1);
